<template>
	<view>
		<u-loading-page loading-mode="semicircle" :loading="loading" color='#57E3A8' loading-text="请稍等"></u-loading-page>
		<view v-show="!loading">
			<view class="category-list">
				<view class="search_list" :style="{height: 120 + 'rpx'}">
					<input type="text" v-model="reqData.title" placeholder="需要搜索什么吗" @input="toSearch"/>
				</view>
				<scroll-view  scroll-y="true" class="left">
			        <view class="row" v-for="(category,findex) in categories" :key="findex" v-show="category.children.length > 0">
						<view class="text">
							<view class="block"></view>
							<text style="text-align: center;font-size: 28rpx;font-weight: 700;background-color: #A9F187;" >{{category.name}}</text>
							<view class="slecket"  :class="[cindex==showCategoryIndex && findex === fIndex?'on':'']" @tap="showCategory(cindex,findex,item.id)" v-for="item,cindex in category.children" :key='cindex'>
								{{item.name}}
							</view>
						</view>
					</view>
					
			    </scroll-view>
				<!-- 右侧子导航 -->
				<scroll-view  scroll-y="true" class="right" lower-threshold='25rpx' @scrolltolower='searchBottom'>
					<view style="height: 500rpx;width: 100%;display: flex;align-items: flex-end;justify-content: center;" v-show="miniLoainng==false">
						<u-loading-icon text="加载中" textSize="18"></u-loading-icon>
					</view>
					<view style="height: 500rpx;width: 100%;display: flex;align-items: flex-end;justify-content: center;color: #D9D9D9;font-weight: 700;" v-show=" goods.data&&goods.data.length == 0&&!miniLoainng==false">
						这里什么都没有
					</view>
				    <view class="category"  v-show="!miniLoainng">
						<view class="list">
							<view class="box" v-for="(box,i) in goods.data" :key="i" @click="toCategory(box)">
								<image :src="box.cover_url"></image>
								<view class="text">{{box.title}}</view>
							</view>
						</view>
					</view>
				</scroll-view>
			</view>
		</view>
	</view>
</template>
<script>
	export default {
		data() {
			return {
				reqData:{
					category_id:'',
					page:1,
					title:'',
					},
				showCategoryIndex:-1,
				fIndex:-1,
				headerPosition:"fixed",
				categories:[],
				goods:{},
				recommend_goods:[],
				timer:0,
				loading:true,
				miniLoainng:true
			}
		},
		onPageScroll(e){
			//兼容iOS端下拉时顶部漂移
			if(e.scrollTop>=0){
				this.headerPosition = "fixed";
			}else{
				this.headerPosition = "absolute";
			}
		},
		onLoad() {
			this.getListGoodsData()
		},
		methods: {
			//消息列表
			async getListGoodsData(){
				const {categories,goods,recommend_goods} = await uni.$u.api.reqListGoodsData(this.reqData)
				let oldGoods = this.goods.data
				this.categories = categories
				this.goods = goods 
				oldGoods ? this.goods.data = oldGoods.concat(this.goods.data) : ''
				this.recommend_goods = 	this.recommend_goods.concat(recommend_goods) 
				this.reqData.page = goods.current_page
				this.loading = false
				this.miniLoainng = false
			},
			searchBottom(){
				this.reqData.page++
				this.getListGoodsData()
			},
			toMsg(){
				uni.navigateTo({
					url:'../../msg/msg'
				})
			},
			//分类切换显示
			showCategory(index,findex,id){
				if(index === this.showCategoryIndex)return
				this.showCategoryIndex = index
				this.fIndex = findex
				this.reqData.category_id = id
				this.goods={},
				this.reqData.page = 1
				this.recommend_goods=[]
				this.reqData.title = ''
				this.miniLoainng = true
				this.getListGoodsData()
			},
			toCategory({id}){
				uni.navigateTo({
					url: `../../pagesLogin/detial/detial?id=${id}`
				});
			},
			//搜索跳转
			toSearch(){
				clearTimeout(this.timer)
				this.timer = setTimeout(()=>{
					this.miniLoainng = true
					this.recommend_goods = []
					this.getListGoodsData()
				},500)
			}
		}
	}
</script>
<style lang="scss">
uni-page-wrapper::after{
	display: none !important;
}
.slecket{
	height: 100rpx;
	width: 100%;
	display: flex;
	justify-content: center;
	align-items: center;
}
	.search_list{
		background-color: #F9F871;
		width: 100%;
		display: flex;
		justify-content: center;
		align-items: center;
		input{
			width: 90%;
			height: 70%;
			border-radius: 50rpx;
			background-color: #00CFC5;
			font-weight: 700;
			text-align: center;
		}
	}
	.status {
		width: 100%;
		height: 0;
		position: fixed;
		z-index: 10;
		background-color: #fff;
		top: 0;
		/*  #ifdef  APP-PLUS  */
		height: var(--status-bar-height);//覆盖样式
		/*  #endif  */
		
	}

	.header{
		width: 92%;
		padding: 0 4%;
		height: 100rpx;
		display: flex;
		align-items: center;
		position: fixed;
		top: 0;
		z-index: 10;
		background-color: #fff;
		/*  #ifdef  APP-PLUS  */
		top: var(--status-bar-height);
		/*  #endif  */
		
		.addr{
			width: 120rpx;
			height: 60rpx;
			flex-shrink: 0;
			display: flex;
			align-items: center;
			font-size: 28rpx;
			.icon{
				height: 60rpx; 
				margin-right: 5rpx;
				display: flex;
				align-items: center;
				font-size: 42rpx;
				color: #ffc50a;
			}
		}
		.input-box{
			width: 100%;
			height: 60rpx;
			background-color: #f5f5f5;
			border-radius: 30rpx;
			position: relative;
			display: flex;
			align-items: center;
			.icon{
				display: flex;
				align-items: center;
				position: absolute;
				top:0;
				right: 0;
				width: 60rpx;
				height: 60rpx;
				font-size: 34rpx;
				color: #c0c0c0;
			}
			input{
				padding-left: 28rpx;
				height: 28rpx;
				font-size: 28rpx;
			}
		}
		.icon-btn{
			width: 60rpx;
			height: 60rpx;
			flex-shrink: 0;
			display: flex;
			.icon{
				width: 60rpx;
				height: 60rpx;
				display: flex;
				justify-content: flex-end;
				align-items: center;
				font-size: 42rpx;
			}
		}
	}
	.place{
		
		background-color: #ffffff;
		height: 100rpx;
		/*  #ifdef  APP-PLUS  */
		margin-top: var(--status-bar-height);
		/*  #endif  */
	}
	.category-list{
		width: 100%;
		background-color: #fff;
		display: flex;
		.left,.right{
			position: absolute;
			
			top: 120rpx;
			/*  #ifdef  APP-PLUS  */
			top: calc(150rpx; + var(--status-bar-height));
			/*  #endif  */
			bottom: 0rpx;
		}
		.left{
			width: 24%;
			left: 0rpx;
			margin-top: 0;
			display: flex;
			justify-content: center;
			.row{
				width: 90%;
				display: flex;
				border-radius: 20rpx;
				margin: 10rpx 0;
				align-items: center;
				overflow: hidden;
				background-color: #57E3A8;
				.text{
					width: 100%;
					position: relative;
					font-size: 28rpx;
					display: flex;
					flex-direction: column;
					justify-content: center;
					color: #3c3c3c;
				}
				.on{
					background-color: #259ECE;
					color: white;
					font-weight: 700;
				}
			}
		}
		.right{
		   width: 76%;
			left: 24%;
			.category{
				width: 94%;
				padding: 20rpx 3%;
				.banner{
					display: none;
					width: 100%;
					height: 24.262vw;
					border-radius: 10rpx;
					overflow: hidden;
					box-shadow: 0rpx 5rpx 20rpx rgba(0,0,0,0.3);
					image{
						width: 100%;
						height: 24.262vw;
					}
				}
				.list{
					margin-top: 40rpx;
					width: 100%;
					display: flex;
					flex-wrap: wrap;
					.box{
						background-color: white;
						width: 45%;
						margin: 10rpx;
						border-radius: 30rpx;
						height: 200rpx;
						margin-bottom: 30rpx;
						display: flex;
						justify-content: center;
						align-items: center;
						flex-wrap: wrap;
						
						image{
							width: 60%;
							height: 70%;
						}
						.text{
							margin-top: 5rpx;
							width: 100%;
							display: flex;
							justify-content: center;
							font-size: 26rpx;
						}
					}
				}
			}
		}
	}
page{
	background-color: #F9F871;
}
</style>
